﻿<?php
	require_once("../class/mysql_help.class.php");
	require_once("../config/config.php");
	class Admin
	{
		var $sqlHelper;
		
		/*构造函数*/
		public function __construct()
		{
			$this->sqlHelper = new db_Mysql();
		}
		
		/*登陆*/
		public function Login($userName,$password)
		{
			global $pre_md5;//将加密前缀从全局变量里引入进来
			$cmd = "Select * From admin Where username = '".$userName."'";
			$this->sqlHelper->dbconnect();
			$result = $this->sqlHelper->execute($cmd);
			$this->sqlHelper->dbclose();
			$row = $this->sqlHelper->fetch_array($result);
			$this->sqlHelper->free_result($result);
			$judge = is_array($row);
			//$pass = md5($password.$pre_md5);
			//echo '<script>alert("'.$pass.'")</script>';
			if($judge?(md5($password.$pre_md5) == $row["password"]):false)
			{
				//登陆成功,返回登录者的id
				return (int)$row["id"];
			}
			else return -1;
		}
	}
?>